/// 回答数据模型
/// 包含回答ID、问题ID、回答者ID、回答内容、点赞数等信息
class AnswerEssence {
  final String id;
  final String questionId;
  final String userId;
  final String content;
  final int likeCount;
  final DateTime createTime;

  AnswerEssence({
    required this.id,
    required this.questionId,
    required this.userId,
    required this.content,
    this.likeCount = 0,
    required this.createTime,
  });

  /// 从Map创建AnswerEssence
  factory AnswerEssence.fromMap(Map<String, dynamic> map) {
    return AnswerEssence(
      id: map['id'] as String,
      questionId: map['questionId'] as String,
      userId: map['userId'] as String,
      content: map['content'] as String,
      likeCount: map['likeCount'] as int? ?? 0,
      createTime: DateTime.parse(map['createTime'] as String),
    );
  }

  /// 转换为Map
  Map<String, dynamic> toMap() {
    return {
      'id': id,
      'questionId': questionId,
      'userId': userId,
      'content': content,
      'likeCount': likeCount,
      'createTime': createTime.toIso8601String(),
    };
  }

  /// 复制并更新部分字段
  AnswerEssence copyWith({
    String? id,
    String? questionId,
    String? userId,
    String? content,
    int? likeCount,
    DateTime? createTime,
  }) {
    return AnswerEssence(
      id: id ?? this.id,
      questionId: questionId ?? this.questionId,
      userId: userId ?? this.userId,
      content: content ?? this.content,
      likeCount: likeCount ?? this.likeCount,
      createTime: createTime ?? this.createTime,
    );
  }
}
